package com.shangma.exercise;


import java.util.Scanner;

/**
 * @classname:demo01
 * @description:
 * @author: Mr.Z
 * @date: 2020/11/25 20:10
 * @version: 0.1
 * @since:1.8
 */
public class bigmoney {

    private static String NAME;
    private static int PASSWORD;
    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        String answer;
        boolean register =false;
        boolean login = false;
        do {
            System.out.println("********欢迎进入大富翁系统********");
            System.out.println("             1.注册              ");
            System.out.println("             2.登录              ");
            System.out.println("             3.抽奖              ");
            System.out.println("*********************************");
            System.out.print("请选择菜单：");
            int choice = input.nextInt();

            switch (choice) {
                case 1:
                    System.out.println("[奖富翁系统 > 注册]");
                    register = register(input);
                    break;
                case 2:
                    System.out.println("[奖富翁系统 > 登录]");
                     login  = login(input, register);
                    break;
                case 3:
                    System.out.println("[奖富翁系统 > 抽奖]");
                    lucky(input,login);
                    break;
                default:
                    System.out.println("您的输入有误！");
                    break;
            }
            System.out.println("继续吗？ （y/n）");
             answer = input.next();
        }while("y".equals(answer));

        input.close();
    }

    private static void lucky(Scanner input,boolean loginFlag) {
        //不予要重复登录
        //是否切换用户
        if(!loginFlag){
            System.out.println("需要先执行登录");
            return;
        }

        System.out.print("请输入会员卡号：");
        int num= input.nextInt();
        int[] nums = new int[5];
        for (int i = 0; i < 5; i++) {
             nums[i] = (int)((Math.random()*9+1)*1000);
        }
        System.out.println("本日幸运数字为："+nums[0]+"\t"+nums[1]+"\t"+nums[2]+"\t"+nums[3]+"\t"+nums[4]);
        for (int i = 0; i < 5; i++) {
            if(num==nums[i]){
                System.out.println("恭喜您成为本日幸运会员");
                break;
            }
        }
        System.out.println("抱歉您不是当日的会员");

    }

    private static boolean login(Scanner input,boolean refisterFlag) {
        //在userRegister里面要是main里面input变量
        // (使用数组维护: 所有的用户注册信息  维护起来 )
        // 保证用户名唯一
        if(input==null){
            return false;
        }
        if(!refisterFlag) {
            System.out.println("需要先注册");
            return false;
        }

        int count = 3;
        while (count>0){
            System.out.print("请输入用户名：");
            String sName = input.next();
            System.out.print("密码：");
            int spassWord = input.nextInt();
            if(NAME.equals(sName)&&PASSWORD==spassWord){
                System.out.println("欢迎您:"+NAME);
                return true;
            }else{
                count--;
                System.out.println("密码错误，还有"+count+"次错误");
            }
        }
        return false;

    }

    private static boolean register(Scanner input) {
        if(input==null){
            return false;
        }
        System.out.println("请填写个人注册信息");
        System.out.print("用户名：");
         NAME = input.next();
        System.out.print("密码：");
         PASSWORD = input.nextInt();
        int random = (int)(Math.random()*10000);
        System.out.println("注册成功，请记好您的会员卡号");
        System.out.println("用户名\t密码\t\t会员卡号");
        System.out.println(NAME+"\t\t"+PASSWORD+"\t\t"+random);
        return true;
    }
}
